package Multithread.Thread.TwoPhaseTermination;

import java.util.concurrent.locks.LockSupport;

//        不推荐使用以下两种终止线程的方法
//        stop会直接杀死线程，如果线程给共享资源加了锁，那共享资源将无法释放
//        System.exit(int)终止整个程序
//        应尽量使用两阶段终止模式，如下：
public class Thread021 {
    public void fun01() throws InterruptedException {
        System.out.println("this is fun01");
        twoPhaseTermination01 t1 = new twoPhaseTermination01();

        t1.start();

        Thread.sleep(3500);

        t1.stop();
    }

    public void fun02() throws InterruptedException {
        System.out.println("this is funThread02");
        Thread t1 = new Thread(()->{
            System.out.println("park……");
//            锁
            LockSupport.park();
            System.out.println("unpark");
            System.out.println("park is untie");
            System.out.println("isInterrupted is " + Thread.currentThread().isInterrupted());

            LockSupport.park();
            System.out.println("unpark");

        },"t1");
        t1.start();

        Thread.sleep(1000);

//        interruptl可以打断pack锁
        t1.interrupt();

    }

}
